import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

/* 1. 引入项目初始化样式 */
/* 1.1 @ 脚手架项目别称，代表 src目录 
   1.2 webpack 处理
*/
import "@/assets/styles/reset.css";
Vue.config.productionTip = false;
/* 2. 引入移动端适配库 lib-flexible */
import "lib-flexible";
// 3. 引入请求库，并且挂在Vue 原型上面，以后每个Vue实例中，可以直接引用请求实例
import instance from "@/api/instance";
Vue.prototype.$request = instance;
// 配置全局前置导航守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  if (to.meta.auth) {
    let token = localStorage.getItem("myToken");
    if (token) {
      next();
    } else {
      next({
        path: "/login-password",
        query: {
          url: window.location.href,
        },
      });
    }
  } else {
    next();
  }
});
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
